package com.zy.ivideo.repository;

import com.zy.ivideo.entity.AgreeEntity;
import com.zy.ivideo.entity.CommentEntity;
import com.zy.ivideo.entity.ResponseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<CommentEntity,Long> {

    @Query(nativeQuery=true,value="select * from b_comment where datatype=?1 and itemid=?2")
    List<CommentEntity> getCommentById(int datatype,String itemid);

    @Transactional
    @Modifying(clearAutomatically=true)
    @Query(value="update b_comment set replytotal=replytotal+?2 where id=?1",nativeQuery=true)
    int modifyReplytotal(Long commentid,int num);

    @Transactional
    @Modifying(clearAutomatically=true)
    @Query(value="update b_comment set agreenum=agreenum+?2 where id=?1",nativeQuery=true)
    int modifyAgreeNum(int commentid,int num);
}
